package com.game.animation;

import com.game.basic.BasicRegion;
import com.game.utils.AnimationInterpolatorUtil;

public class AnimationTranslate extends Animation{

	public static final int TYPE_TRANSFORM_ACCELERATION_ADD=0;//加速
	public static final int TYPE_TRANSFORM_ACCELERATION_MIN=1;//减速
	protected float tran_x;//x轴移动的距离
	protected float tran_y;//y轴移动的距离
	//此时间为现实世界的时间
	protected int type;
	
	public AnimationTranslate(AnimationFix animationfix,AnimationCallBack animationCallBack,float tran_x,float tran_y,float time,int type,boolean keep) {
		this(animationfix,animationCallBack,tran_x,tran_y,time,type,0,keep);
	}
	
	public AnimationTranslate(AnimationFix animationfix,AnimationCallBack animationCallBack,float tran_x,float tran_y,float time,int type,float delayTime,boolean keep) {
		super(animationfix, animationCallBack,delayTime,keep,time);
		this.tran_x=tran_x;
		this.tran_y=tran_y;
		this.type=type;
		this.animationType=ANIMATION_TYPE_TRANSLATE;
	}
	
	@Override
	protected void step() {
		if(time_step<=time){
			float input = time_step/time;
			float perc=0;
			switch (type) {
			case TYPE_TRANSFORM_ACCELERATION_ADD:
				//加速算法
				perc=AnimationInterpolatorUtil.getAccelerate(input);
				break;
			case TYPE_TRANSFORM_ACCELERATION_MIN:
				//减速算法
				perc=AnimationInterpolatorUtil.getDecelerate(input);
			default:
				break;
			}
			animationfix.setTransx(perc*tran_x);
			animationfix.setTransy(perc*tran_y);
		}
	}

	@Override
	protected void keepState() {
		BasicRegion r=animationfix.getReferenceRegion();
		r.setPostx(r.getPostx()+tran_x);
		r.setPosty(r.getPosty()+tran_y);
	}
	
}
